//================v2要点总结===============
/**
 * 1. 用前序遍历
 */

/**
 * Definition for a binary tree node.
 */
// function TreeNode(val, left, right) {
//     this.val = (val === undefined ? 0 : val)
//     this.left = (left === undefined ? null : left)
//     this.right = (right === undefined ? null : right)
// }
/**
 * @param {TreeNode} root1
 * @param {TreeNode} root2
 * @return {TreeNode}
 */
var mergeTrees = function (root1, root2) {
    function preOrder(node1, node2) {
        let currentNode = null
        if (!node1 && !node2) {
            return currentNode
        }

        if (!node1 || !node2) {
            currentNode = node1 || node2
        } else {
            node1.val += node2.val
            currentNode = node1
        }

        currentNode.left = preOrder(node1 ? node1.left : null, node2 ? node2.left : null)
        currentNode.right = preOrder(node1 ? node1.right : null, node2 ? node2.right : null)
        return currentNode
    }
    return preOrder(root1, root2)
}


console.log(3, mergeTrees())